<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="./../home.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui">

    <ui:define name="content">
        <p:growl id="msgGrowl"  />
        <div class="col-lg-12">
            <h3 class="page-header" id="comercio">
                Administración de Serenos
            </h3>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <h:form id="frmFiltroSereno" styleClass="form-horizontal">
                    <p:panel header="Busqueda de Sereno" styleClass="panel panel-primary" toggleable="true" toggleSpeed="300">
                        <div class="row">
                            <div class="col-md-12" >
                                <div class="col-md-1" style="width: 10.733333333333332%;text-align: right;" >
                                    <label class="control-label" style="font-weight: normal;" for="startTime">Nombre:</label>
                                </div>
                                <div class="col-md-4" style="margin-right: -45px;margin-left: -5px;"  >
                                    <p:inputText value="#{serenoBean.serenoFiltro.nombre}" />
                                </div>
                                <div class="col-md-1" style="width: 10.733333333333332%;text-align: right;" >
                                    <label class="control-label" style="font-weight: normal;" for="startTime">Apellidos:</label>
                                </div>
                                <div class="col-md-4" style="margin-right: -45px;margin-left: -5px;"  >
                                    <p:inputText value="#{serenoBean.serenoFiltro.apellido}" />
                                </div>
                            </div>
                        </div>
                        <br/>
                        <p:panelGrid columns="2">
                            <h:commandButton styleClass="btn btn-primary" value="Buscar" actionListener="#{serenoBean.buscarFiltro}">
                                <f:ajax execute="@form" render=":frmSerenoLst :msgGrowl" />
                            </h:commandButton>
                            <h:commandButton styleClass="btn btn-primary" value="Limpiar" actionListener="#{serenoBean.limpiarFiltro}">
                                <f:ajax execute="@form" render=":frmSerenoLst :frmFiltroSereno :msgGrowl" />
                            </h:commandButton>
                        </p:panelGrid>                        
                    </p:panel>  
                </h:form>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-sm-2">
                                <h:panelGroup rendered="#{usuarioBean.permiso.crear eq true}">
                                    <h:button value="Nuevo Sereno" styleClass="btn btn-primary" outcome="create.xhtml" />
                                </h:panelGroup>
                            </div>
                        </div>
                        <p:spacer height="10" />
                        <h:form id="frmSerenoLst">
                            <f:event type="preRenderView" listener="#{serenoBean.initLista()}"/>
                            <p:dataTable value="#{serenoBean.serenos}" var="list" paginator="true" rows="10" lazy="true" rowIndexVar="rowIndex"
                                         paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                                         emptyMessage="No hay serenos resgitrados">
                                <f:facet name="header">
                                    <h:commandLink styleClass="btnExportarExcel" actionListener="#{serenoBean.exportar}">
                                        <h:graphicImage value="/resources/image/xls.gif" />
                                    </h:commandLink>
                                </f:facet>
                                <p:column style="text-align: center;">
                                    <f:facet name="header">
                                        #
                                    </f:facet>
                                    <h:outputText value="#{rowIndex+1}" />
                                </p:column>
                                <p:column style="text-align: left;">
                                    <f:facet name="header">
                                        Nombre
                                    </f:facet>
                                    <h:outputText value="#{list.nombre}" />
                                </p:column>
                                <p:column style="text-align: left;">
                                    <f:facet name="header">
                                        Apellidos
                                    </f:facet>
                                    <h:outputText value="#{list.apellido}" />
                                </p:column>
                                <p:column style="text-align: center;">
                                    <h:panelGroup rendered="#{usuarioBean.permiso.actualizar eq true}">
                                        <p:commandButton icon="icon-update" action="#{serenoBean.irActualizar(list.id)}"/>
                                    </h:panelGroup>
                                    <h:panelGroup rendered="#{usuarioBean.permiso.eliminar eq true}">
                                        <p:commandButton icon="icon-delete" title="Eliminar" actionListener="#{serenoBean.prepararEliminar(list.id)}" oncomplete="dlgSere.show();"  style="font-size: 13px;" />
                                    </h:panelGroup>
                                </p:column>
                            </p:dataTable>
                        </h:form>
                    </div>
                </div>
            </div>
        </div>
        <p:dialog modal="true" maximizable="false" widgetVar="dlgSere" header="Eliminar Registro">
            <p>¿Desea eliminar al Sereno?</p>
            <h:form id="frmEliminar">
                <p:commandButton value="Aceptar" actionListener="#{serenoBean.eliminarSereno}" update=":frmSerenoLst,:msgGrowl" oncomplete="dlgSere.hide();" />
                <p:commandButton value="Cancelar" oncomplete="dlgCan.hide();" />
            </h:form>
        </p:dialog>
    </ui:define>

</ui:composition>
